home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 5_6.lha / 5_6 / 5_6b.c < prev    next >
Text File  |  1993-08-08  |  786b  |  45 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. / implement a character queue using
  6. / an array
  7. include <char_queue.h>
  8. include <error.h>
  9.  
  10. har_queue:: char_queue(int nummembers)
  11.  
  12.    base = new char[nummembers];
  13.    end = &base[nummembers];
  14.    front = rear = base;
  15.  
  16.  
  17. har_queue:: ~char_queue()
  18.  
  19.    delete base;
  20.  
  21.  
  22. oid char_queue:: enqueue(char c)
  23.  
  24.    *rear++ = c;
  25.    if (rear == end)
  26.        rear = base;
  27.    if (rear == front)
  28.        error("overflow of character queue");
  29.  
  30.  
  31. har char_queue:: dequeue()
  32.  
  33.    if (emptyQ())
  34.        error("underflow of character queue");
  35.    char ch = *front++;
  36.    if (front == end)
  37.        front = base;
  38.    return ch;
  39.  
  40.  
  41. oid char_queue:: clearQ()
  42.  
  43.    front = rear = base;
  44.  
  45.